import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  UseGuards,
  Put,
} from '@nestjs/common';
import { SizeService } from './size.service';
import { CreateSizeDto } from './dto/create-size.dto';
import { UpdateSizeDto } from './dto/update-size.dto';
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
import { AuthGuard } from '@nestjs/passport';
import { QueryPageDto } from '../../common/dto/query.page.dto';
import { Prisma } from '@prisma/client';
import { QuerySizeDto } from './dto/query-size.dto';

@Controller('size')
@ApiTags('尺寸管理管理')
@UseGuards(AuthGuard('jwt'))
@ApiBearerAuth()
export class SizeController {
  constructor(private readonly sizeService: SizeService) {}

  @Post()
  @ApiOperation({
    summary: '创建尺寸',
  })
  create(@Body() createSizeDto: CreateSizeDto) {
    return this.sizeService.createModel(createSizeDto);
  }

  @Post('page')
  findByPage(@Body() query: QueryPageDto<QuerySizeDto>) {
    const where: Prisma.sizeWhereInput = {
      name: {
        contains: query.model.name || undefined,
      },
    };

    return this.sizeService.queryPage(query, where);
  }

  @Get()
  findAll() {
    return this.sizeService.findAll();
  }

  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.sizeService.findOne(id);
  }

  @Put(':id')
  update(@Param('id') id: string, @Body() updateSizeDto: UpdateSizeDto) {
    return this.sizeService.updateModel(id, updateSizeDto);
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.sizeService.delete(id);
  }
}
